/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
 int count(struct TreeNode *root) {
    if (root == NULL) return 0;
    return count(root->left) + count(root->right) + 1;
 }

int kthLargest(struct TreeNode* root, int k){
    int r_size = count(root->right);
    if (r_size >= k) return kthLargest(root->right, k);
    if (r_size + 1 == k) return root->val;
    return kthLargest(root->left, k - r_size - 1);
}
